import java.util.ArrayList;
import java.util.List;

/**
 * 1876. 长度为三且各字符不同的子字符串
 * https://leetcode-cn.com/problems/substrings-of-size-three-with-distinct-characters/
 */
public class Solutions_1876 {
    public static void main(String[] args) {
        String s1 = "xyzzaz";  // output: 1
        String s2 = "aababcabc";  // output: 4

        List<String> inputs = new ArrayList<>();
        inputs.add(s1);
        inputs.add(s2);

        for (String input : inputs) {
            int result = countGoodSubstrings(input);
            System.out.println(result);
        }
    }

    public static int countGoodSubstrings(String s) {
        char[] arr = s.toCharArray();
        int count = 0;

        for (int i = 2; i < arr.length; i++) {
            char a = arr[i];
            char b = arr[i - 1];
            char c = arr[i - 2];
            if (a == b || b == c || a == c) {
                continue;
            }
            // 3 个字符互不相同，即是好子字符串
            count ++;
        }
        return count;
    }
}
